(*
Source file: BasicUtils.fs
October, 2012
Authors:	Jorge Fabian Maciel Hernandez	967153
		Esteban Perez Mejia		1163982

*)
module BASICUtils

open System.IO
open BASICLexer
open BASICParser

type SymbolTable =
    | ScalarTable of Set<string>
    | FunctionTable of Set<string>
    | ArrayTable of Map<string, int>
    | MatrixTable of Map<string,(int * int)>

let parseString text = 
    lineNumber <- ref 1
    let lexbuf = Lexing.LexBuffer<char>.FromString text
    try 
        start token lexbuf 
        //token lexbuf
    with e ->  
        let endPos = lexbuf.EndPos
        let column = endPos.Column
        let lastToken = new System.String(lexbuf.Lexeme)
        failwithf "Error in line %d. Problem with token: '%s'. %s" !lineNumber lastToken e.Message
        
let parseFile filename =
    let text = File.ReadAllText(filename)
    parseString text
    
let writeFile filename content =
    File.WriteAllText(filename, content)
